<template>
  <div class="supplier-form-container">
    <div class="form-header">
      <h1 class="form-title">{{ pageTitle }}</h1>
    </div>
    <div class="form-card">
      <form @submit.prevent="submitForm" class="supplier-form">
        <div class="form-section">
          <div class="form-group">
            <label for="companyName">供应商名称 *</label>
            <input 
              type="text" 
              id="companyName" 
              v-model="formData.companyName" 
              required 
              placeholder="请输入供应商名称"
              :class="{ 'error': errors.companyName }"
            />
            <div v-if="errors.companyName" class="error-message">{{ errors.companyName }}</div>
          </div>

          <div class="form-group">
            <label for="phone">电话 *</label>
            <input 
              type="tel" 
              id="phone" 
              v-model="formData.phone" 
              required 
              placeholder="请输入联系电话"
              :class="{ 'error': errors.phone }"
            />
            <div v-if="errors.phone" class="error-message">{{ errors.phone }}</div>
          </div>

          <div class="form-group">
            <label for="project">项目 *</label>
            <input 
              type="text" 
              id="project" 
              v-model="formData.project" 
              required 
              placeholder="请输入参与项目"
              :class="{ 'error': errors.project }"
            />
            <div v-if="errors.project" class="error-message">{{ errors.project }}</div>
          </div>
        </div>

        <div class="form-section">
          <h2 class="section-title">人力配置</h2>
          <div class="form-row">
            <div class="form-group half-width">
              <label for="manpower">总人力 *</label>
              <input 
                type="number" 
                id="manpower" 
                v-model.number="formData.manpower" 
                required 
                min="0"
                placeholder="请输入总人力"
                :class="{ 'error': errors.manpower }"
              />
              <div v-if="errors.manpower" class="error-message">{{ errors.manpower }}</div>
            </div>

            <div class="form-group half-width">
              <label for="分割人力">分割人力 *</label>
              <input 
                type="number" 
                id="分割人力" 
                v-model.number="formData.segmentedManpower" 
                required 
                min="0"
                placeholder="请输入分割人力"
                :class="{ 'error': errors.segmentedManpower }"
              />
              <div v-if="errors.segmentedManpower" class="error-message">{{ errors.segmentedManpower }}</div>
            </div>
          </div>

          <div class="form-row">
            <div class="form-group half-width">
              <label for="pointCloudManpower">3D点云人力 *</label>
              <input 
                type="number" 
                id="pointCloudManpower" 
                v-model.number="formData.pointCloudManpower" 
                required 
                min="0"
                placeholder="请输入3D点云人力"
                :class="{ 'error': errors.pointCloudManpower }"
              />
              <div v-if="errors.pointCloudManpower" class="error-message">{{ errors.pointCloudManpower }}</div>
            </div>

            <div class="form-group half-width">
              <label for="weekReportCount">周内报道人数 *</label>
              <input 
                type="number" 
                id="weekReportCount" 
                v-model.number="formData.weekReportCount" 
                required 
                min="0"
                placeholder="请输入周内报道人数"
                :class="{ 'error': errors.weekReportCount }"
              />
              <div v-if="errors.weekReportCount" class="error-message">{{ errors.weekReportCount }}</div>
            </div>
          </div>
        </div>

        <button type="submit" class="submit-btn">提交报名信息</button>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SupplierForm',
  data() {
    return {
      formData: {
        companyName: '',
        phone: '',
        project: '',
        manpower: null,
        segmentedManpower: null,
        pointCloudManpower: null,
        weekReportCount: null
      },
      errors: {}
    }
  },
  computed: {
    pageTitle() {
      // 从URL参数获取标题，如果没有则使用默认值
      const urlParams = new URLSearchParams(window.location.search);
      return urlParams.get('title') || '山东盛拓科技有限公司';
    }
  },
  methods: {
    validateForm() {
      this.errors = {};
      
      if (!this.formData.companyName) {
        this.errors.companyName = '供应商名称不能为空';
      }
      
      if (!this.formData.phone) {
        this.errors.phone = '电话不能为空';
      } else if (!/^1[3-9]\d{9}$/.test(this.formData.phone)) {
        this.errors.phone = '请输入正确的手机号码';
      }
      
      if (!this.formData.project) {
        this.errors.project = '项目不能为空';
      }
      
      if (this.formData.manpower === null || this.formData.manpower < 0) {
        this.errors.manpower = '人力必须为非负数';
      }
      
      if (this.formData.segmentedManpower === null || this.formData.segmentedManpower < 0) {
        this.errors.segmentedManpower = '分割人力必须为非负数';
      }
      
      if (this.formData.pointCloudManpower === null || this.formData.pointCloudManpower < 0) {
        this.errors.pointCloudManpower = '3D点云人力必须为非负数';
      }
      
      if (this.formData.weekReportCount === null || this.formData.weekReportCount < 0) {
        this.errors.weekReportCount = '周内报道人数必须为非负数';
      }
      
      return Object.keys(this.errors).length === 0;
    },
    submitForm() {
      if (this.validateForm()) {
        // 这里可以添加表单提交逻辑
        console.log('提交的表单数据:', this.formData);
        alert('报名信息已提交成功！');
        
        // 重置表单
        this.formData = {
          companyName: '',
          phone: '',
          project: '',
          manpower: null,
          segmentedManpower: null,
          pointCloudManpower: null,
          weekReportCount: null
        };
      } else {
        alert('请检查表单填写是否正确');
      }
    }
  }
}
</script>

<style scoped>
.supplier-form-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf9 100%);
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

.form-header {
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  padding: 40px 20px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

.form-header::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
  transform: rotate(30deg);
}

.form-title {
  color: white;
  font-size: 32px;
  font-weight: 700;
  margin: 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-card {
  background: #ffffff;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 100%;
  max-width: 800px;
  margin: -30px auto 40px;
  border-radius: 16px;
  animation: fadeInUp 0.6s ease-out;
  position: relative;
  overflow: hidden;
  border: 1px solid #edf2f7;
}

.form-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.form-group {
  animation: fadeIn 0.5s ease-out;
  animation-fill-mode: backwards;
}

.form-group:nth-child(1) {
  animation-delay: 0.1s;
}

.form-group:nth-child(2) {
  animation-delay: 0.2s;
}

.form-group:nth-child(3) {
  animation-delay: 0.3s;
}

.supplier-form {
  display: flex;
  flex-direction: column;
}

.form-section {
  margin-bottom: 30px;
  padding: 25px;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  border: 1px solid #e2e8f0;
  transition: all 0.3s ease;
}

.form-section:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  border-color: #cbd5e0;
}

.section-title {
  color: #2d3748;
  font-size: 22px;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #e2e8f0;
  position: relative;
  display: inline-block;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 50px;
  height: 2px;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
}

.form-group {
  margin-bottom: 25px;
}

.form-row {
  display: flex;
  gap: 25px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.half-width {
  flex: 1;
  min-width: 250px;
}

label {
  display: block;
  margin-bottom: 10px;
  font-weight: 600;
  color: #2d3748;
  text-align: left;
  font-size: 15px;
  position: relative;
  padding-left: 10px;
}

label::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  background: #6a11cb;
  border-radius: 50%;
}

input {
  width: 100%;
  padding: 15px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 16px;
  transition: all 0.3s ease;
  box-sizing: border-box;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  font-family: inherit;
  position: relative;
}

input:focus {
  outline: none;
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
  transform: translateY(-1px);
  background: #ffffff;
}

input:hover {
  border-color: #cbd5e0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

input::placeholder {
  color: #a0aec0;
  font-style: italic;
}

input.error {
  border-color: #e53e3e;
  background: #fff5f5;
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.error-message {
  color: #e53e3e;
  font-size: 14px;
  text-align: left;
  margin-top: 8px;
  font-weight: 500;
  display: flex;
  align-items: center;
}

.error-message::before {
  content: '!';
  display: inline-block;
  width: 18px;
  height: 18px;
  background: #e53e3e;
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  line-height: 18px;
  margin-right: 8px;
}

.submit-btn {
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  color: white;
  border: none;
  padding: 18px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 10px;
  box-shadow: 0 4px 15px rgba(37, 117, 252, 0.3);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
}

.submit-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: 0.5s;
}

.submit-btn:hover::before {
  left: 100%;
}

.submit-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 25px rgba(37, 117, 252, 0.4);
  background: linear-gradient(135deg, #7a1bdb 0%, #3585ff 100%);
}

.submit-btn:active {
  transform: translateY(0);
  box-shadow: 0 4px 15px rgba(37, 117, 252, 0.2);
}

.submit-btn:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(66, 153, 225, 0.3);
}

@media (max-width: 768px) {
  .form-header {
    padding: 30px 15px;
  }
  
  .form-title {
    font-size: 26px;
  }
  
  .form-card {
    padding: 25px;
    margin: -20px 15px 30px;
  }
  
  .form-section {
    padding: 20px;
  }
  
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .half-width {
    min-width: 100%;
  }
  
  .section-title {
    font-size: 20px;
  }
  
  input {
    padding: 14px;
  }
  
  .submit-btn {
    padding: 16px;
  }
}
</style>